﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class GB03GBData : BaseFunction
    {


        public GB03GBData()
            : base()
        {

        }

        public GB03GBData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public DataSet BuildData(DataRow dwThis)
        {
            DataSet setReturn = new DataSet();
            DataSet dsResult = new DataSet();
            try
            {

                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT GPEINDAT,CODE,GLLB,GLLP,ART,VAR,BEZ,COLOR,SUPPLIER,SUPPLIERBATCH,LOT,ROUND(SUM(WEI),2) AS WEI "
                    + " FROM WAREHOUSE_YARN_REPORT_DETAIL  WHERE GLLB NOT IN ('JS','12','13') "
                    + " GROUP BY GPEINDAT,CODE,GLLB,GLLP,ART,VAR,BEZ,COLOR,SUPPLIER,SUPPLIERBATCH,LOT  order by color,art"
                                ;
                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = "YARN_INVENTORY";
                    byte[] b;
                    string value;
                    string ColumnName = "";
                    foreach (DataRow dwTemp in dsResult.Tables["YARN_INVENTORY"].Rows)
                    {
                        ColumnName = "BEZ";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                        ColumnName = "SUPPLIER";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                        ColumnName = "COLOR";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                    }
                }
                setReturn.Merge(dsResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}